package cn.jsj.fixed.asset;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 报销设备处理类
 * @author LI
 *
 */
 public class WipeOutAsset extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
	 public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 调试信息
		 cn.jsj.utils.SysLogger.PrintInfo("报销设备！！！！");

		 //获取参数
		 int fixedAssetId=Integer.parseInt(request.getParameter("fixedAssetId").trim());
		 int wipeoutNumber=Integer.parseInt(request.getParameter("wipeOutNumb").trim());

		 //新建参数类对象
		 cn.jsj.bgtodb.WipeAssetProperty wap=new cn.jsj.bgtodb.WipeAssetProperty();
		 wap.setFixedAssetId(fixedAssetId);
		 wap.setWipeoutNumber(wipeoutNumber);
		 //调试信息
		 cn.jsj.utils.SysLogger.PrintInfo("canshu------------->"+fixedAssetId+"         "+wipeoutNumber);

		 //获得这种设备的总数（或者是剩余数）
		 cn.jsj.dao.TblFixedAssetsDAO tfad=new cn.jsj.dao.TblFixedAssetsDAO();
		 int leftNumber=tfad.getLeftNumber(fixedAssetId);

		 //调试信息
		 cn.jsj.utils.SysLogger.PrintInfo("剩余数------------->"+leftNumber);
		 //输出流
		 java.io.PrintWriter out=response.getWriter();
		 //判断报销数量是否大于总数
		 if(wipeoutNumber>leftNumber){
			 out.println("{message:'报销数量大于总数，操作失败！'}");
			 out.flush();
			 out.close();
			 return;
		 }

		 //增加报销信息
		int saveResult= tfad.wipeOutAsset(wap);

		//如果报销成功
		if(saveResult==1){
			out.println("{message:'报销成功！'}");
		}else{
			out.println("{message:'报销失败！'}");
		}
		out.flush();
		out.close();
	}
}